#pragma once
#include "IReadingInformation.h"
#include <list>
#include <set>
#include <queue>
#include <sstream>
#include <exception>
#include <memory>
#include <map>
#include <Windows.h>
#include "IReading.h"
#include "DatabaseManager.h"


namespace Sensor {

	class ReadingInformation : public virtual IReadingInformation {
	private:
		HANDLE readingQueueMutex;
		std::queue<std::unique_ptr<IReading>> readingQueue;
		std::map<std::string, std::unique_ptr<IReading>> lastReadingMap;
		DatabaseManager databaseManager;
	public:		
		ReadingInformation();

		virtual void update();
		virtual std::list<std::unique_ptr<IReading>> getReading(const int sensorId, const std::string readingType, const ITime& start, const ITime& end) const;
		virtual double getReadingAverage(const int sensorId, const std::string readingType, const ITime& start, const ITime& end) const {
			return this->databaseManager.getReadingAverage(sensorId, readingType, start, end);
		}
		
		virtual std::set<std::string> getReadingTypes() const;
		virtual std::set<int> getSensorIds(const ITime& start, const ITime& end) const;
		virtual void onReading(unique_ptr<IReading>& reading);

	};

}